import re

phone_num_regex_01 = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d')
phone_num_regex_02 = re.compile(r'\d{3}-\d{3}-\d{4}')
phone_num_regex_02 = re.compile(r'(\d{3}-)?\d{3}-\d{4}')
str1 = 'My number is 415-555-4242.'
str2 = 'My number is 555-4242.'
# mo = phone_num_regex_01.search(str1)
mo1 = phone_num_regex_02.search(str1)
mo2 = phone_num_regex_02.search(str2)
print(mo1.group())
print(mo2.group())
